package cn.itcast.search.controller;

import cn.itcast.hmall.dto.common.PageDTO;
import cn.itcast.hmall.dto.common.ResultDTO;
import cn.itcast.hmall.dto.search.SearchReqDTO;
import cn.itcast.hmall.pojo.item.ItemDoc;
import cn.itcast.search.service.EsMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/search")
@Slf4j
public class EsSearch {
    @Autowired
    private EsMapper esMapper;

    @GetMapping("importItemData")
    public ResultDTO importItemData() {
        return this.esMapper.importData();
    }
    @GetMapping("/suggestion")
    public List<String>suggestion(@RequestParam String key){
        return this.esMapper.suggestionList(key);
    }
    @PostMapping("/filters")
    public Map<String,List<String>>filters(@RequestBody SearchReqDTO dto){
        return this.esMapper.filters(dto);
    }
    @PostMapping("/list")
    public PageDTO<ItemDoc>list(@RequestBody SearchReqDTO dto){

        PageDTO<ItemDoc>it=this.esMapper.list(dto);
        return it;
    }
}
